﻿<phone:PhoneApplicationPage
    x:Class="Locima.SlidingBlock.GameEditor"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewModel="clr-namespace:Locima.SlidingBlock.ViewModel"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True"
    Style="{StaticResource TransitionPageStyle}">

    <phone:PhoneApplicationPage.Resources>
        <viewModel:GameEditorViewModel x:Key="ViewModel" />
    </phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{Binding Source={StaticResource ViewModel}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle"
                       Text="{Binding Path=Strings.ApplicationName, Source={StaticResource Localization}}"
                       Style="{StaticResource PhoneTextNormalStyle}" />
            <TextBlock x:Name="PageTitle"
                       Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"
                       Text="{Binding Path=Strings.GameEditorPageTitle, Source={StaticResource Localization}}" />
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <StackPanel x:Name="ContentPanel" Margin="12,0,12,0" Grid.Row="1">
            <TextBlock Text="{Binding Path=Strings.GameName, Source={StaticResource Localization}}" />
            <TextBox x:Name="GameTitle" Text="{Binding Title, Mode=TwoWay, UpdateSourceTrigger=Explicit}" TextChanged="ControlChanged" IsEnabled="{Binding IsEditable}" />
            <TextBlock Text="{Binding Path=Strings.AuthorName, Source={StaticResource Localization}}" />
            <TextBox x:Name="GameAuthor" Text="{Binding Author, Mode=TwoWay, UpdateSourceTrigger=Explicit}" TextChanged="ControlChanged" IsEnabled="{Binding IsEditable}" />
            <TextBlock Text="{Binding Path=Strings.LevelList, Source={StaticResource Localization}}" />
        </StackPanel>

        <ScrollViewer Grid.Row="2" Margin="24,0,12,0">
            <ListBox x:Name="LevelsListBox" ItemsSource="{Binding LevelList}"
                     SelectionChanged="LevelsListBoxSelectionChanged"
                     ScrollViewer.VerticalScrollBarVisibility="Disabled">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="0,12,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Border Grid.Column="0" BorderBrush="{StaticResource PhoneForegroundBrush}" BorderThickness="1">
                                <Image Source="{Binding Path=Thumbnail}" Width="64" Height="64" />
                            </Border>
                            <StackPanel Grid.Column="1" Margin="10,0,0,0">
                                <TextBlock Text="{Binding Path=ImageTitle}" />
                                <TextBlock Text="{Binding Path=ImageText}" />
                            </StackPanel>
                            <toolkit:ContextMenuService.ContextMenu>
                                <toolkit:ContextMenu Name="MyContextMenu">
                                    <!-- Can't use IsEnabled binding to IsEditable because of a defect in the silverlight toolkit, have to do it using ICommand CanExecute instead -->
                                    <toolkit:MenuItem Header="{Binding Path=Strings.MoveLevelUp, Source={StaticResource Localization}}" Command="{Binding MoveLevelCommand}" CommandParameter="-1" />
                                    <toolkit:MenuItem Header="{Binding Path=Strings.MoveLevelDown, Source={StaticResource Localization}}" Command="{Binding MoveLevelCommand}" CommandParameter="1" />
                                    <toolkit:MenuItem Header="{Binding Path=Strings.AddLevelBefore, Source={StaticResource Localization}}" Command="{Binding AddLevelBeforeCommand}" />
                                    <toolkit:MenuItem Header="{Binding Path=Strings.AddLevelAfter, Source={StaticResource Localization}}" Command="{Binding AddLevelAfterCommand}" />
                                    <toolkit:MenuItem Header="{Binding Path=Strings.DeleteLevel, Source={StaticResource Localization}}" Command="{Binding DeleteLevelCommand}" />
                                </toolkit:ContextMenu>
                            </toolkit:ContextMenuService.ContextMenu>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </ScrollViewer>
    </Grid>


</phone:PhoneApplicationPage>